﻿using System;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QuanLyTuyenSinh.PresentationLayer.Components
{
    public partial class frmDiemchuan : Form
    {
       SqlConnection Conn;
        string sql;
        public frmDiemchuan()
        {
            InitializeComponent();
        }

      
        private void frmDiemchuan_Load(object sender, EventArgs e)
        {
            //Conn = ConnectData.Getcon();
            //Conn.Open();
            //comboManganh.DataSource=nganhthibus.LayManganhUngVoiTruong("SP2");
            //comboManganh.ValueMember = "Manganh";
            //comboManganh.DisplayMember = "Manganh";
            //sql = "delete BangDiemDo delete BangDiemTruot";
            //SqlCommand Cmd = new SqlCommand(sql, Conn);
            //Cmd.ExecuteNonQuery();
        }

        private void cmdLayDS_Click(object sender, EventArgs e)
        {
            try
            {
                if ((txtChitieu.Text == "") || (int.Parse(txtChitieu.Text) <= 0))
                {
                    MessageBox.Show("Nhập chỉ tiêu!");
                }
                else
                {
                    SqlCommand Cmd;
                    sql = "drop table BangDiemDo" + comboManganh.Text.Trim() + " SELECT TOP (" + txtChitieu.Text.Trim() + ")SBD,Phongthi,Hodem,Ten,Truongdkdt,Khtruong,Khoithi,Manganh,Tennganh,Gioitinh,Ngaysinh,Noisinh,Dantoc,Mauutien," +
                                  "Diemdoituong,Hokhau,Tentinh,Mahuyen,Namtotnghiep,Lop10,Lop11,Lop12,Noinophoso,Dienthoai,Makhuvuc,Diemkhuvuc," +
                                  "DiemM1,DiemM2,DiemM3,DiemM1+DiemM2+DiemM3 as 'Tong1',DiemM1+DiemM2+DiemM3+Diemdoituong+Diemkhuvuc as 'TongCT' " +
                                  " into BangDiemDo" + comboManganh.Text.Trim() + " from TSSBD where Manganh='" + comboManganh.Text.Trim() + "' and Khtruongnv='' order by DiemM1+DiemM2+DiemM3+Diemdoituong+Diemkhuvuc desc" +
                                  " insert into BangDiemDo select * from BangDiemDo" + comboManganh.Text.Trim() + "";
                    Cmd = new SqlCommand(sql, Conn);
                    Cmd.ExecuteNonQuery();      
                    MessageBox.Show("Tạo danh sách trúng tuyển mã ngành " + comboManganh.Text.Trim() + " xong!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void comboManganh_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        private void cmdDSTruot_Click(object sender, EventArgs e)
        {
            try
            {
                if ((txtChitieu.Text == "") || (int.Parse(txtChitieu.Text) <= 0))
                {
                    MessageBox.Show("Nhập chỉ tiêu!");
                }
                else
                {
                    SqlCommand Cmd;
                    //int So_ban_ghi = thisinhbus.GetDSTSSBD(comboManganh.Text.Trim()).Rows.Count;
                    //int conlai = So_ban_ghi - int.Parse(txtChitieu.Text.Trim());
                    //sql = "drop table BangDiemTruot" + comboManganh.Text.Trim() + " SELECT Top(" + conlai + ")SBD,Phongthi,Hodem,Ten,Truongdkdt,Khtruong,Khoithi,Manganh,Tennganh,Gioitinh,Ngaysinh,Noisinh,Dantoc,Mauutien," +
                    //             "Diemdoituong,Hokhau,Tentinh,Mahuyen,Namtotnghiep,Lop10,Lop11,Lop12,Noinophoso,Dienthoai,Makhuvuc,Diemkhuvuc," +
                    //             "DiemM1,DiemM2,DiemM3,DiemM1+DiemM2+DiemM3 as 'Tong1',DiemM1+DiemM2+DiemM3+Diemdoituong+Diemkhuvuc as 'TongCT' " +
                    //   " into BangDiemTruot" + comboManganh.Text.Trim() + " from TSSBD where Manganh='" + comboManganh.Text.Trim() + "' and " +
                    //   " Khtruongnv='' order by DiemM1+DiemM2+DiemM3+Diemdoituong+Diemkhuvuc" +
                    //   " insert into BangDiemTruot select * from BangDiemTruot" + comboManganh.Text.Trim() + "";
                    //Cmd = new SqlCommand(sql, Conn);
                    //Cmd.ExecuteNonQuery();
                    //MessageBox.Show("Tạo danh sách thí sinh không trúng tuyển mã ngành " + comboManganh.Text.Trim() + " xong!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}